package com.greyu.ysj.service.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.greyu.ysj.entity.CbtChangeDraw;
import com.greyu.ysj.entity.CbtChangeDrawExample;
import com.greyu.ysj.entity.CbtChangeExample;
import com.greyu.ysj.mapper.CbtChangeDrawMapper;
import com.greyu.ysj.service.CbtChangeDrawService;

@Service
public class CbtChangeDrawServiceImpl implements CbtChangeDrawService{
@Autowired
private CbtChangeDrawMapper cbtChangeDrawMapper;
	@Override
	public List<CbtChangeDraw> getChangeRecord(Integer userId, Integer page, Integer rows) {
		// TODO Auto-generated method stub
		if (null != page && null != rows) {
            PageHelper.startPage(page, rows);
        }
		CbtChangeDrawExample cbtChangeDrawExample = new CbtChangeDrawExample();
		CbtChangeDrawExample.Criteria criteria = cbtChangeDrawExample.createCriteria();
		criteria.andUserIdEqualTo(userId);
		cbtChangeDrawExample.setOrderByClause("`create_date` DESC");
		return cbtChangeDrawMapper.selectByExample(cbtChangeDrawExample);
	}

	@Override
	public int totalPages(Integer userId, Integer rows) {
		// TODO Auto-generated method stub
		CbtChangeDrawExample cbtChangeDrawExample = new CbtChangeDrawExample();
		CbtChangeDrawExample.Criteria criteria =cbtChangeDrawExample.createCriteria();
		criteria.andUserIdEqualTo(userId);
		long total=this.cbtChangeDrawMapper.countByExample(cbtChangeDrawExample);
		int totalPages;
		if(total%rows == 0) {
			totalPages=(int) (total/rows);
		}else {
			totalPages=(int) (total/rows)+1;
		}
		System.out.println("totalPages_change=>"+totalPages);
		return totalPages;
	}

}
